package logic

import (
	"context"
	"group/models"

	"group/internal/svc"
	"group/pb/group"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateGroupLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateGroupLogic {
	return &UpdateGroupLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// UpdateGroup 更新群聊
func (l *UpdateGroupLogic) UpdateGroup(in *group.GroupInfo) (*group.Empty, error) {
	err := l.svcCtx.ChatGroupAggregationModel.UpdateGroup(l.ctx, &models.ChatGroup{
		Id:       in.Id,
		UserId:   in.UserId,
		Name:     in.Name,
		Avatar:   in.Avatar,
		Desc:     in.Desc,
		Status:   in.Status,
		JoinType: in.JoinType,
	})
	if err != nil {
		return nil, err
	}
	return &group.Empty{}, nil
}
